package com.yun.datastructure.tree.heap.leetcode;

import com.yun.datastructure.tree.heap.MinHeap;

public class Leetcode215 {
    public int findKthLargest(int[] nums,int k){
        MinHeap heap=new MinHeap(k);
        for (int i = 0; i < k; i++) {
            heap.offer(nums[i]);
        }
        for (int i = k; i < nums.length; i++) {
            if(nums[i]>heap.peek()){
                heap.replace(nums[i]);
            }
        }
        return heap.peek();
    }

    public static void main(String[] args) {
        int[] array = {3,2,3,1,2,4,5,5,6};
        int k=4;
        int res=new Leetcode215().findKthLargest(array,k);
        System.out.println(res);
    }
}
